﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Windows;
using Ecng.Common;
using Ecng.Serialization;
using Ecng.Xaml;
using Sample.TradingClasses;
using StockSharp.Algo.Candles;
using System.Linq;
using System.Windows.Forms;
using StockSharp.BusinessEntities;
using MessageBox = System.Windows.Forms.MessageBox;
using StockSharp.Algo.Storages;
namespace Sample.StartTrading
{
    /// <summary>
    /// Логика взаимодействия для OpenRobot.xaml
    /// </summary>
    public partial class OpenRobot : Window
    {
        public OpenRobot(String NewRobotName)
        {
            InitializeComponent();
   //         Portfolio.Trader = MainWindow.Instance.Trader;

            RobotString = "Oткрытие Робота-";

            _getStore = new SettingsStorage(); ///////////////////// VERY IMPORTANT

            RobotFileName = NewRobotName;
            savedinfoXMLfile = new ssXmlStorage(RobotFileName);

            GetDataNewRobot();
        }

        private ssXmlStorage savedinfoXMLfile;// = new ssXmlStorage("");
        public SettingsStorage _getStore;
        public String RobotFileName = "";
        public string RobotString = "";

//     public Security Security { get; set; }
        
        private void GetDataNewRobot()
        {
            savedinfoXMLfile.FileToRead = RobotFileName;
            var _getStore = new XmlSerializer<SettingsStorage>().Deserialize(RobotFileName);

            savedinfoXMLfile.Load(_getStore);

            x_RobotName.Content = savedinfoXMLfile.RobotName;
            x_Type.Content = savedinfoXMLfile.RobotType;
            x_Mode.Content = savedinfoXMLfile.RobotMode;
            x_RobotCreatingDateTime.Content = savedinfoXMLfile.RobotDateTimeCreating;
            Title = RobotString + x_Type.Content.ToString();

     //       Security.ItemsSource = MainWindow.Instance._securitiesWindow.Securities;
        }

        protected override void OnClosed(EventArgs e)
        {
            //          _openRobot.DeleteHideable();
            //            _openRobot.Close();

            base.OnClosed(e);
        }


        private void LimitOrder_Click(object sender, RoutedEventArgs e)
        {
            //var security = (Security)SecuritiesDetails.SelectedValue;
 //           var security = (Security) x_Security.SelectionBoxItem;
//            var newOrder = new NewOrderWindow { Title = "Новая заявка на '{0}'".Put(security.Code), Security = security };
            var newOrder = new NewOrderWindow { Title = "LimitOrder"};
            newOrder.ShowModal(this);
        }

        private void StopOrder_Click(object sender, RoutedEventArgs e)
        {
            /*
            var security = (Security)x_Security.SelectionBoxItem;
            var newOrder = new NewStopOrderWindow
            {
                Title = "Новая заявка на '{0}'".Put(security.Code),
                Security = security,
            };
            */

            var newOrder = new NewStopOrderWindow { Title = "StopOrder" };
            newOrder.ShowModal(this);

        }

    }

}
